#!/usr/bin/env python3

from configparser import ConfigParser

import os
import pydantic as pd

__all__ = ["config"]

config_path = os.path.join(os.path.dirname(__file__), "config.ini")

class ConfigureDatabase(pd.BaseModel):
  host: str
  user: str
  password: str
  database: str

  @classmethod
  def load(cls, data: dict):
    return cls(**data)

def load_config(*, path: pd.FilePath = config_path, section: str = "config_stu") -> ConfigureDatabase:
  config_ini = ConfigParser()

  with open(path, 'r', encoding="utf-8") as f:
    config_ini.read(path)

  return ConfigureDatabase.load(config_ini._sections[section])

config = load_config()
